﻿using System;
using System.Text;

namespace CodeAngel.Domain
{
    /// <summary>
    /// Used to build up SQL text that can be used in stored procedures.
    /// </summary>
    public class SqlStringBuilder
    {
        #region Add

        /// <summary>
        /// Adds text to the current line.  No new line will be created.
        /// </summary>
        public void Add(string value)
        {
            this._stringBuilder.Append(value);
        }

        /// <summary>
        /// Adds text to the current line, followed by a new line.
        /// </summary>
        public void AddLine(string value)
        {
            this._stringBuilder.AppendLine(value);
        }

        /// <summary>
        /// Adds a blank line.
        /// </summary>
        public void AddBlankLine()
        {
            this._stringBuilder.Append(Environment.NewLine);
        }

        #endregion

        #region AddComment

        /// <summary>
        /// Adds the text as a comment. 
        /// </summary>
        public void AddComment(string text)
        {
            this._stringBuilder.AppendLine("--" + text);
        }

        /// <summary>
        /// Adds the text as a comment block (comment surrounded by conspicuous separation). 
        /// </summary>
        public void AddCommentBlock(string text)
        {
            this.AddBlankLine();
            this._stringBuilder.Append('-', 100);
            this.AddBlankLine();
            this._stringBuilder.AppendLine("--" + text);
            this._stringBuilder.Append('-', 100);
            this.AddBlankLine();
        }

        #endregion

        #region _stringBuilder

        private StringBuilder _stringBuilder = new StringBuilder();

        #endregion

        #region ToString

        public override string ToString()
        {
            return this._stringBuilder.ToString();
        }

        #endregion

    }
}
